<?php
if ($paginator->itemsCount > $paginator->limit) {
    ?>
    <div class="paginator">
        <ul>
            <?php
            if ($paginator->currentPage != 1) {
                ?>   
                <li> <a class="previous" href="<?php echo $view['router']->generate($controller, array('page' => $paginator->currentPage - 1)) ?>">Previous</a></li>
                <?php
            }


            for ($i = 1; $i <= $paginator->numPages; $i++) {
                if ($paginator->range[0] > 2 and $i == $paginator->range[0])
                    echo '<li>...</li>';

                if ($i == 1 or $i == $paginator->numPages or in_array($i, $paginator->range)) {
                    if ($i == $paginator->currentPage) {
                        ?>
                        <li><span class="active" ><?php echo $i; ?></span></li>
                        <?php
                    } else {
                        ?>
                        <li><a href="<?php echo $view['router']->generate($controller, array('page' => $i)); ?>"> <?php echo $i; ?></a></li>
                        <?php
                    }
                }

                if ($paginator->range[$paginator->midRange - 1] < $paginator->numPages - 1 and $i == $paginator->range[$paginator->midRange - 1])
                    echo '<li>...</li>';
                else if ($paginator->currentPage == end($paginator->range))
                    $end = true;
            }

            if (!isset($end) || $end != true) {
                ?>
                <li> <a class="next" href="<?php echo $view['router']->generate($controller, array('page' => $paginator->currentPage + 1)) ?>">Next</a></li>
                <?php
            }
            ?>
        </ul>
    </div>
    <?php
}
?>